<template>
	<div class="chartNum">
		<h3 class="orderTitle">{{title}}</h3>
		<div class="box-item">
			<li :class="{'number-item': !isNaN(item), 'mark-item': isNaN(item) }" v-for="(item,index) in orderNum"
				:key="index">
				<span v-if="!isNaN(item)">
					<i ref="numberItem">0123456789</i>
				</span>
				<span class="comma" v-else>{{item}}</span>
			</li>
		</div>
	</div>
</template>
<script>
	export default {
		props: {
			title:{
				type:String,
				default () {
					return false
				}
			},
			gundongDatas: {
				type:Number,
				default () {
					return false
				}
			},
		},
		watch: {
			gundongDatas: function(newVal, oldVal) {
				// console.log(newVal,'newVal')
				this.toOrderNum(newVal)
			},
			
		},
		data() {
			return {
				// gundongData: this.gundongDatas,
				orderNum: ['0',',','0','0', '0', ',', '0', '0', '0', ',', '0', '0', '0'], // 默认订单总数
			}
		},
		created() {

		},
		mounted() {
			var that = this;
			
		},
		methods: {
			// 设置文字滚动
			setNumberTransform() {
				const numberItems = this.$refs.numberItem // 拿到数字的ref，计算元素数量
				const numberArr = this.orderNum.filter(item => !isNaN(item))
				// 结合CSS 对数字字符进行滚动,显示订单数量
				for (let index = 0; index < numberItems.length; index++) {
					const elem = numberItems[index]
					elem.style.transform = `translate(-50%, -${numberArr[index] * 10}%)`
				}
			},
			// 处理总订单数字
			toOrderNum(num) {
				var num = num.toString()
				// 把订单数变成字符串
				if (num.length < 10) {
					num = '0' + num // 如未满八位数，添加"0"补位
					this.toOrderNum(num) // 递归添加"0"补位
				} else if (num.length === 10) {
					// 订单数中加入逗号
					num = num.slice(0, 1) + ','+ num.slice(1, 4) + ',' + num.slice(4, 7) + ',' + num.slice(7, 10)
					this.orderNum = num.split('') // 将其便变成数据，渲染至滚动数组
					this.setNumberTransform();
				} else {
					// 订单总量数字超过八位显示异常
					this.$message.warning('数字过大，显示异常，请联系客服')
				}
			},
		},
		
	}
</script>
<style scoped>
	.chartNum{
		display: flex;
		align-items: center;
		/* width: 100%; */
	}
	.orderTitle {
		font-size: .14rem;
		color: #00FFFF;
		width: .35rem;
	}

	/*订单总量滚动数字设置*/
	.box-item {
		position: relative;
		height: .3rem;
		font-size: .22rem;
		line-height: .3rem;
		text-align: center;
		list-style: none;
		color: #fff;
		
		writing-mode: vertical-lr;
		text-orientation: upright;
		/*文字禁止编辑*/
		-moz-user-select: none;
		/*火狐*/
		-webkit-user-select: none;
		/*webkit浏览器*/
		-ms-user-select: none;
		/*IE10*/
		-khtml-user-select: none;
		/*早期浏览器*/
		user-select: none;
		/* overflow: hidden; */
	}

	/* 默认逗号设置 */
	.mark-item {
		width: .1rem;
		height: .3rem;
		/* margin-right: 0.1rem; */
		line-height: .3rem;
		font-size: .26rem;
		position: relative;
	}

	.mark-item>span {
		position: absolute;
		width: 100%;
		bottom: -0.08rem;
		left: .1rem;
		writing-mode: vertical-rl;
		text-orientation: upright;
	}

	/*滚动数字设置*/
	.number-item {
		width: .24rem;
		height: .3rem;
		background: #ccc;
		list-style: none;
		margin-right: 0.05rem;
		background: #28565b;
		/* border-radius: .04rem; */
		/* border:1px solid rgba(221,221,221,1); */

	}

	.number-item>span {
		position: relative;
		display: inline-block;
		margin-right: .05rem;
		width: 100%;
		height: 100%;
		writing-mode: vertical-rl;
		text-orientation: upright;
		overflow: hidden;
		text-decoration: overline;
	}

	.number-item>span>i {
		font-style: normal;
		position: absolute;
		top: .04rem;
		left: 50%;
		transform: translate(-50%, 0);
		transition: transform 1s ease-in-out;
		letter-spacing: .1rem;

	}

	.number-item:last-child {
		margin-right: 0;
	}
</style>
